Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
how to Sequelize "where" accessing table and column

I am attempting to port an application that had used sequelize 3.30.4 and I'm updating to 6.13, I'm assuming some things have changed because I can't use string literals in a where clause, or so the debugger tells me.

That said, I've done some googling and have found some basic examples that make sense sure but I'm not entirely sure how to convert this string to a format acceptable for findAndCountAll to be happy.

I've attempted something like this, thinking it might at least point me in the right direction however it does not.


  let attributes = ['id', 'name', 'locationId'];
  let where = undefined;
  let order = [['name', 'ASC']];

    where = {
      classroom: {
        locationId: request.query.locationId
      }
    }

this is the line that did at one time work but no longer works.

where = `"classroom"."locationId" = ${request.query.locationId}`;
  const classrooms = await model.classroom.findAndCountAll(_.assign({},
    requestHelper.computePaginationObject(request.query.limit, request.query.page), {
    attributes,
    where: where ? [where] : undefined,
    order
  }));

how would I go about porting this into the proper format?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Try something like this:

let where = {}
if (<some condition>) {
  where = {
    locationId: request.query.locationId
  }
}
const classrooms = await model.classroom.findAndCountAll(_.assign({},
    requestHelper.computePaginationObject(request.query.limit, request.query.page), {
    attributes,
    where: where,
    order
  }));
about 4 years ago · Juan Pablo Isaza Relatório

0

You can also try that even if the first comment of ANATOLY works wonders :

const where = <some condition> ? {locationId: request.query.locationId} :{};

const classrooms = await model.classroom.findAndCountAll(_.assign({},
        requestHelper.computePaginationObject(request.query.limit, request.query.page), {
        attributes,
        where,
        order
      }));
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda